package com.barnabe;

import java.io.*;
import java.util.*;

public class WindowsUtils {

    public static void abrirMiddleware() throws IOException {

        String line;
        boolean estaAberto = false;
        Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = input.readLine()) != null) {
            if (!line.trim().equals("")) {
                // keep only the process name
                line = line.substring(1);
                if (line.substring(0, line.indexOf("\"")).equals("Middleware.exe")) {
                    estaAberto = true;
                    break;
                }

            }

        }
        input.close();
        if (!estaAberto) {

            //Runtime.getRuntime().
            Runtime.getRuntime().exec("..\\middleware\\bin\\Middleware.exe");
        }


    }
}